package cn.bus.service.impl;

import cn.bus.domain.Customer;
import cn.bus.mapper.CustomerMapper;
import cn.bus.service.CustomerService;
import cn.bus.vo.CustomerVo;
import cn.sys.utils.DataGridView;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Mxb
 * @version 1.0
 * @date 2019/11/2 21:09
 */
@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public DataGridView queryAllCustomer(CustomerVo customerVo) {
        Page<Object> page = PageHelper.startPage(customerVo.getPage(), customerVo.getLimit());
        List<Customer> data = customerMapper.queryAllCustomer(customerVo);
        return new DataGridView(page.getTotal(), data);
    }

    @Override
    public void addCustomer(CustomerVo customerVo) {
        this.customerMapper.insertSelective(customerVo);
    }

    @Override
    public void updateCustomer(CustomerVo customerVo) {
        this.customerMapper.updateByPrimaryKeySelective(customerVo);
    }

    @Override
    public void deleteCustomerById(String id) {
        this.customerMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void deleteBatchCustomer(String[] ids) {
        for (String id : ids) {
            this.customerMapper.deleteByPrimaryKey(id);

        }
    }

    @Override
    public Customer queryCustomerById(String id) {
        return this.customerMapper.selectByPrimaryKey(id);
    }
}
